<template>
	<view class="coupon" :class="type">
		<view class="bg-color" :style="{ background: color }"></view>
		<view class="left-dot"></view>
		<view class="right-dot" :style="{ background: color }"></view>
		<view class="left-tag text-center" :style="{ background: color }">
			{{tag}}
			<image class="tag" src="@/static/images/cp-tag.png" style="width: 100%;" mode="widthFix"></image>
		</view>
		
		<view class="btn" @click="onClick">
			{{btn}}
		</view>

		<view class="main">
			<view class="left">
				<view class="amount" :style="{ color: color }">
					{{amount}}
				</view>
			</view>
			<view class="right">
				<view class="text-gray text">满{{threshold}}可用</view>
				<view class="text-gray text-xs">有效期至：</view>
				<view class="text-gray text-xs">{{expire}}</view>
			</view>
			<view class="sell" v-if="sell">
				
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			type: {
				type: String,
				default: ''
			},
			amount: {
				type: [Number, String],
				default: ''
			},
			threshold: {
				type: [Number, String],
				default: 0
			},
			expire: {
				type: String,
				default: ''
			},
			btn: {
				type: String,
				default: ''
			},
			sell: {
				type: [Number, String],
				default: 0
			}
		},
		data() {
			return {
				translate: [{
					name: '影视',
					type: 'film',
					color: '#FD8C15'
				}, {
					name: '设计',
					type: 'development',
					color: '#77C1FF'
				}, {
					name: '企划',
					type: 'agent',
					color: '#EDBE80'
				}, {
					name: '物料',
					type: 'materials',
					color: '#FF7A79'
				}, {
					name: '服务',
					type: 'service',
					color: '#37D0CA'
				}, {
					name: '通用',
					type: 'cash',
					color: '#7b8c7c'
				}],
				color: '#FD8C15',
				tag: ''
			};
		},
		mounted() {
			let arr = this.translate
			let res = arr.find(item => item.type==this.type)
			this.color = res.color
			this.tag = res.name
		},
		methods: {
			onClick() {
				this.$emit('click');
			},
		}
	}
</script>

<style lang="scss">
	.coupon {
		width: 670rpx;
		height: 180rpx;
		margin: 0 auto;
		margin-top: 40rpx;
		border-radius: 8rpx;
		position: relative;
		&:nth-last-of-type(1) {
			margin-bottom: 40rpx;
		}

		.bg-color {
			width: 100%;
			height: 100%;
			border-radius: 12rpx;
			position: absolute;
			z-index: 1;
		}

		.left-dot,
		.right-dot {
			width: 60rpx;
			height: 60rpx;
			border-radius: 50%;
			position: absolute;
			z-index: 3;
			transform: translate(-50%, -50%);
		}

		.left-dot {
			left: -8rpx;
			top: 50%;
			background: #EFF1F4;
		}

		.right-dot {
			right: 8rpx;
			top: 50%;
		}

		.left-tag {
			width: 40rpx;
			height: 80rpx;
			position: absolute;
			z-index: 3;
			top: -6rpx;
			left: 32rpx;
			color: #fff;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 22rpx;

			.tag {
				position: absolute;
				bottom: 0;
				display: block;
			}
		}
		
		.btn {
			width: 80rpx;
			padding: 0 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #fff;
			height: 100%;
			position: absolute;
			z-index: 3;
			font-size: 28rpx;
			text-align: center;
			right: 0;
		}

		.main {
			width: 594rpx;
			height: 100%;
			position: absolute;
			z-index: 2;
			background: #fff;
			border-radius: 12rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;
			letter-spacing: 2rpx;

			.left {
				width: 180rpx;
				height: 100%;
				display: flex;
				justify-content: flex-end;
				align-items: center;
			}

			.right {
				width: 300rpx;
				height: 70%;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				align-items: center;
			}

			.amount {
				font-size: 40rpx;
				font-weight: bold;
				position: relative;

				&::after {
					content: '￥';
					position: absolute;
					z-index: 3;
					font-size: 20rpx;
					top: 0rpx;
					right: -32rpx;
					transform: translate(-50%, -50%);
				}
			}
		}
	}
</style>
